import com.boyi.shared.util.RandomUtil;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author 颜培轩
 * @date 2018年08月16日  上午 10:57
 */
public class thread {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(1);
        ExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1000, Executors.defaultThreadFactory());
        for (int i = 0; i < 1000; i++)
            scheduledExecutorService.execute(new Runnable() {
                @Override
                public void run() {
                    while (true)
                        try {
                            Thread.sleep(Integer.valueOf(RandomUtil.getRandom(0, 10)) * 1000);
                            countDownLatch.countDown();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                }
            });
        countDownLatch.await();
    }
}
